import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author LKQ
 * @date 2022/2/22 21:50
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        String[] strings = new String[]{"5","2","C","D","+"};
        solution.calPoints(strings);
    }
    public int calPoints(String[] ops) {
        List<Integer> list = new ArrayList<>();
        for (String op: ops) {
            if (Objects.equals(op, "C")) {
                list.remove(list.size() - 1);
            }else if (Objects.equals(op, "D")) {
                int lastPoint = list.get(list.size() - 1);
                list.add(lastPoint * 2);
            }else if (Objects.equals(op, "+")) {
                int lastP1 = list.get(list.size() - 2), lastP2 = list.get(list.size() - 1);
                list.add(lastP1 + lastP2);
            }else {
                list.add(Integer.parseInt(op));
            }
        }
        int sum = 0;
        for (Integer integer : list) {
            sum += integer;
        }
        return sum;
    }
}
